import { defHttp } from '/@/common/util/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  list = '/sys/msg/getPage',
  save = '/sys/msg/add',
  edit = '/sys/msg/edit',
  editMsgSend = '/sys/msg/editMsgSend',
  delete = '/sys/msg/delete',
  deleteBatch = '/sys/msg/deleteBatch',
  exportXls = '/sys/msg/exportXls',
  importExcel = '/sys/msg/importExcel',
  releaseMsg = '/sys/msg/releaseMsg',
  reovkeData = '/sys/msg/revokeMsg',
  updateAllUnreadMessage = '/sys/msg/updateAllUnreadMessage',       //全部已读
  getMessageGroupCount = '/sys/msg/getMessageGroupCount',           //分组统计数量
}

/**
 * 导出url
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入url
 */
export const getImportUrl = Api.importExcel;
/**
 * 查询租户列表
 * @param params
 */
export const getList = (params) => {
  return defHttp.get({ url: Api.list, params });
};

/**
 * 保存或者更新通告
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

export const editMsgSend = (params) => defHttp.post({ url: Api.editMsgSend, params });

/**
 * 删除通告
 * @param params
 */
export const deleteNotice = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量消息公告
 * @param params
 */
export const batchDeleteNotice = (params) => defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true });

/**
 * 发布
 * @param id
 */
export const releaseMsg = (params) => defHttp.get({ url: Api.releaseMsg, params });
/**
 * 撤销
 * @param id
 */
export const revokeMsg = (params) => defHttp.get({ url: Api.reovkeData, params });

/**
 * 获取用户近两个月未读消息数量-分组统计
 * @param params
 */
export const getMessageGroupCount = (params?) => defHttp.get({ url: Api.getMessageGroupCount, params });

/**
 * 清空全部未读消息
 */
export const updateAllUnreadMessage = (params?) => {
  Modal.confirm({
    title: '确认操作',
    content: '是否全部标注已读?',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({ url: Api.updateAllUnreadMessage, data: params },{ isTransformResponse: false });
    },
  });
}